package com.bluesky.plum.domain.repository.search.operator;

import java.util.HashMap;
import java.util.Map;

import com.bluesky.plum.richdomain.FieldType;

public class OperatorFactory {
	private Map<FieldType, Class> map;

	static OperatorFactory instance;

	private OperatorFactory() {
		map = new HashMap<FieldType, Class>();

		map.put(FieldType.Boolean, BooleanOperator.class);
		map.put(FieldType.Integer, IntegerOperator.class);
		map.put(FieldType.String, StringOperator.class);
		map.put(FieldType.ObjectReference, ObjectOperator.class);
		map.put(FieldType.Collection, CollectionOperator.class);
	}

	static private OperatorFactory getInstance() {
		if (instance == null)
			instance = new OperatorFactory();

		return instance;
	}

	static public Class getOperators(Class clazz) {
		if (getInstance().map.containsKey(clazz))
			return getInstance().map.get(clazz);
		else
			throw new RuntimeException("no operator for class:"
					+ clazz.getName());
	}
}
